//
//  PostsItemFrame.m
//  JiaoX
//
//  Created by yinqy on 15/3/3.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "PostsItemFrame.h"
#import "TitleStyleView.h"

@implementation PostsItemFrame

-(void)setPosts:(BBSPosts *)posts{
    _posts = posts;
    
    self.titleStyleFrame = (CGRect){{10,15},[TitleStyleView sizeWithTitleStyles:posts.titleStyles]};
    CGFloat titleFrameX = CGRectGetMaxX(self.titleStyleFrame)+ (self.titleStyleFrame.size.width==0?0:5);
    CGFloat titleFrameY = self.titleStyleFrame.origin.y;
    CGFloat titleFrameW = JXScreenW-titleFrameX-10;
    CGFloat titleFrameH = TITLE_FONT.lineHeight;
    
    self.titleFrame = CGRectMake(titleFrameX, titleFrameY, titleFrameW, titleFrameH);
    
    if (posts.top) {
        //是置顶帖
        self.frame = CGRectMake(0, 0, JXScreenW, CGRectGetMaxY(self.titleFrame)+15);
        return;
    }
    
    self.descFrame = CGRectMake(10, CGRectGetMaxY(self.titleFrame)+15, JXScreenW-20, DESC_FONT.lineHeight);
    
    CGFloat currentMaxY = CGRectGetMaxY(self.descFrame);
    
    if (posts.img!=nil && posts.img.count!=0) {
        self.picViewFrame = CGRectMake(0, CGRectGetMaxY(self.descFrame)+10, JXScreenW, (JXScreenW-50)/4);
        currentMaxY = CGRectGetMaxY(self.picViewFrame);
    }
    
    NSString *genderImg = @"ic_gender_small_unknow";
    //判断是男是女
    if ([[NSString stringWithFormat:@"%@",posts.userGender] isEqualToString:@"1"]) {
        genderImg = @"ic_gender_small_man";
    }else if([[NSString stringWithFormat:@"%@",posts.userGender] isEqualToString:@"2"]){
        genderImg = @"ic_gender_small_woman";
    }
    //判断是否是vip
    if (posts.level) {
        genderImg = [NSString stringWithFormat:@"%@_vip",genderImg];
    }
    CGFloat authorW = [UIImage imageNamed:genderImg].size.width+[posts.nickName sizeWithFont:AUTHOR_FONT].width+5;
    self.authorFrame = CGRectMake(10, currentMaxY+10, authorW, AUTHOR_FONT.lineHeight);
    
    
    CGFloat replyCountW = [UIImage imageNamed:@"replyNum_icon_heighlight"].size.width+5+[[NSString stringWithFormat:@"%d",posts.replyNum] sizeWithFont:AUTHOR_FONT].width;
    CGFloat replyCountH = AUTHOR_FONT.lineHeight;
    CGFloat replyCountX = JXScreenW-10-replyCountW;
    CGFloat replyCountY = self.authorFrame.origin.y;
    self.replyCountFrame = CGRectMake(replyCountX, replyCountY, replyCountW, replyCountH);
    
    CGSize replyTimeSize = [posts.replyTime sizeWithFont:AUTHOR_FONT];
    CGFloat replyTimeX = replyCountX - 10- replyTimeSize.width;
    CGFloat replyTimeY = replyCountY;
    self.replyTimeFrame = (CGRect){{replyTimeX,replyTimeY},replyTimeSize};
    
    
    self.frame = CGRectMake(0, 0, JXScreenW, CGRectGetMaxY(self.authorFrame)+15);
}
@end
